package com.lanou.zhihu.web.controller;

import com.lanou.zhihu.entity.User;
import com.lanou.zhihu.service.CommentGoodSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by QuChao on 2018/10/31.
 */
@Controller
@RequestMapping("/commentGood")
public class CommentGoodController {
    @Autowired
    private CommentGoodSevice commentGoodSevice;

    @ResponseBody
    @RequestMapping("/findByUidCid")
    public boolean findByUidCid(Integer cid, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        return commentGoodSevice.findByUidCid(user, cid);
    }

    @ResponseBody
    @RequestMapping("/goodCountByCid")
    public Integer goodCountByCid(Integer cid) {
        return commentGoodSevice.goodCountByCid(cid);
    }

    @ResponseBody
    @RequestMapping("/good")
    public boolean good(Integer cid, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        return commentGoodSevice.good(user, cid);
    }

    @ResponseBody
    @RequestMapping("/cancelGood")
    public boolean cancelGood(Integer cid, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        return commentGoodSevice.cancelGood(user, cid);
    }
}
